package cn.iocoder.yudao.module.system.dal.mysql.otherService;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.otherService.vo.ApiCallCount;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * @Description:
 * @Author: meiwanli
 * @Date: 2025-10-15 15:14
 */
@Mapper
public interface ApiCallCountMapper extends BaseMapperX<ApiCallCount> {

    default int updateByStatisticalTime(ApiCallCount updateObj) {
        return update(updateObj, new LambdaQueryWrapperX<ApiCallCount>()
                .eq(ApiCallCount::getStatisticalTime, updateObj.getStatisticalTime()));

    }

    default ApiCallCount selectByStatisticalTime(String statisticalTime){
        return selectOne(new LambdaQueryWrapperX<ApiCallCount>()
                .eq(ApiCallCount::getStatisticalTime, statisticalTime));
    }

    default List<ApiCallCount> selectApiCallCountList(Integer dayCount){
        return selectList(new QueryWrapper<ApiCallCount>()
                .orderByDesc("statistical_time")
                .last("LIMIT " + dayCount));
    }
}
